﻿using System.Configuration;
using MySqlConnector;

namespace Front._1124;

public partial class Login : Form
{
    

    public Login()
    {
        InitializeComponent();
    }

    

    private void button1_Click_1(object sender, EventArgs e)
    {
        using var connection = new MySqlConnection("server=localhost;port=3306;database=book;user=root;password=root;charset=utf8mb4;AllowPublicKeyRetrieval=True;");
        connection.Open();
        string sql = "select * from admin_info where admin_account=@account and admin_password=@password";
        using var command = new MySqlCommand(sql, connection);
        //设置参数
        command.Parameters.AddWithValue("account", this.textBox1.Text);
        string password = this.textBox2.Text;
        //对密码进行md5加密
        string pwd =MD5Helper.GetMD5(password);
        command.Parameters.AddWithValue("pwd", pwd);
        

        
        using var reader = command.ExecuteReader();
        if (reader.HasRows)
        {
            MainFrom mainFrom = new MainFrom();
            mainFrom.Show();
            this.Hide();
        }
        else
        {
            MessageBox.Show("用户名或密码错误");
            this.textBox1.Text = "";
            this.textBox2.Text = "";
        }
        
    }
}